﻿if exists (select * from dbo.sysobjects where name = 'sp_Work_GetByTop')	drop procedure [dbo].[sp_Work_GetByTop]Go CREATE PROCEDURE dbo.sp_Work_GetByTop
@Top	nvarchar(10),
@Where	nvarchar(200),
@Order	nvarchar(200)
AS
	Declare @SQL as nvarchar(500)
	Select @SQL = 'SELECT top (' + @Top + ') * FROM [Work]'
	if len(@Top) = 0 
		BEGIN
			Select @SQL = 'SELECT * FROM [Document]'
		END
	if len(@Where) >0 
		BEGIN
			Select @SQL = @SQL + ' Where ' + @Where
		END
	if len(@Order) >0
		BEGIN
			Select @SQL = @SQL + ' Order by ' + @Order
		END
	EXEC (@SQL)
Go